import{g as getDocument}from"../shared/ssr-window.esm.min.mjs";import{h as classesToTokens,c as createElement,n as nextTick,b as elementOffset}from"../shared/utils.min.mjs";import{c as createElementIfNotDefined}from"../shared/create-element-if-not-defined.min.mjs";import{c as classesToSelector}from"../shared/classes-to-selector.min.mjs";function Scrollbar(s){let{swiper:l,extendParams:e,on:r,emit:a}=s;const t=getDocument();let o,n,i,c,p=!1,m=null,d=null;function b(){if(!l.params.scrollbar.el||!l.scrollbar.el)return;const{scrollbar:s,rtlTranslate:e}=l,{dragEl:r,el:a}=s,t=l.params.scrollbar,o=l.params.loop?l.progressLoop:l.progress;let c=n,p=(i-n)*o;e?(p=-p,p>0?(c=n-p,p=0):-p+n>i&&(c=i+p)):p<0?(c=n+p,p=0):p+n>i&&(c=i-p),l.isHorizontal()?(r.style.transform=`translate3d(${p}px, 0, 0)`,r.style.width=`${c}px`):(r.style.transform=`translate3d(0px, ${p}px, 0)`,r.style.height=`${c}px`),t.hide&&(clearTimeout(m),a.style.opacity=1,m=setTimeout((()=>{a.style.opacity=0,a.style.transitionDuration="400ms"}),1e3))}function u(){if(!l.params.scrollbar.el||!l.scrollbar.el)return;const{scrollbar:s}=l,{dragEl:e,el:r}=s;e.style.width="",e.style.height="",i=l.isHorizontal()?r.offsetWidth:r.offsetHeight,c=l.size/(l.virtualSize+l.params.slidesOffsetBefore-(l.params.centeredSlides?l.snapGrid[0]:0)),n="auto"===l.params.scrollbar.dragSize?i*c:parseInt(l.params.scrollbar.dragSize,10),l.isHorizontal()?e.style.width=`${n}px`:e.style.height=`${n}px`,r.style.display=c>=1?"none":"",l.params.scrollbar.hide&&(r.style.opacity=0),l.params.watchOverflow&&l.enabled&&s.el.classList[l.isLocked?"add":"remove"](l.params.scrollbar.lockClass)}function f(s){return l.isHorizontal()?s.clientX:s.clientY}function g(s){const{scrollbar:e,rtlTranslate:r}=l,{el:a}=e;let t;t=(f(s)-elementOffset(a)[l.isHorizontal()?"left":"top"]-(null!==o?o:n/2))/(i-n),t=Math.max(Math.min(t,1),0),r&&(t=1-t);const c=l.minTranslate()+(l.maxTranslate()-l.minTranslate())*t;l.updateProgress(c),l.setTranslate(c),l.updateActiveIndex(),l.updateSlidesClasses()}function y(s){const e=l.params.scrollbar,{scrollbar:r,wrapperEl:t}=l,{el:n,dragEl:i}=r;p=!0,o=s.target===i?f(s)-s.target.getBoundingClientRect()[l.isHorizontal()?"left":"top"]:null,s.preventDefault(),s.stopPropagation(),t.style.transitionDuration="100ms",i.style.transitionDuration="100ms",g(s),clearTimeout(d),n.style.transitionDuration="0ms",e.hide&&(n.style.opacity=1),l.params.cssMode&&(l.wrapperEl.style["scroll-snap-type"]="none"),a("scrollbarDragStart",s)}function T(s){const{scrollbar:e,wrapperEl:r}=l,{el:t,dragEl:o}=e;p&&(s.preventDefault?s.preventDefault():s.returnValue=!1,g(s),r.style.transitionDuration="0ms",t.style.transitionDuration="0ms",o.style.transitionDuration="0ms",a("scrollbarDragMove",s))}function h(s){const e=l.params.scrollbar,{scrollbar:r,wrapperEl:t}=l,{el:o}=r;p&&(p=!1,l.params.cssMode&&(l.wrapperEl.style["scroll-snap-type"]="",t.style.transitionDuration=""),e.hide&&(clearTimeout(d),d=nextTick((()=>{o.style.opacity=0,o.style.transitionDuration="400ms"}),1e3)),a("scrollbarDragEnd",s),e.snapOnRelease&&l.slideToClosest())}function v(s){const{scrollbar:e,params:r}=l,a=e.el;if(!a)return;const o=a,n=!!r.passiveListeners&&{passive:!1,capture:!1},i=!!r.passiveListeners&&{passive:!0,capture:!1};if(!o)return;const c="on"===s?"addEventListener":"removeEventListener";o[c]("pointerdown",y,n),t[c]("pointermove",T,n),t[c]("pointerup",h,i)}function D(){const{scrollbar:s,el:e}=l;l.params.scrollbar=createElementIfNotDefined(l,l.originalParams.scrollbar,l.params.scrollbar,{el:"swiper-scrollbar"});const r=l.params.scrollbar;if(!r.el)return;let a,o;if("string"==typeof r.el&&l.isElement&&(a=l.el.querySelector(r.el)),a||"string"!=typeof r.el)a||(a=r.el);else if(a=t.querySelectorAll(r.el),!a.length)return;l.params.uniqueNavElements&&"string"==typeof r.el&&a.length>1&&1===e.querySelectorAll(r.el).length&&(a=e.querySelector(r.el)),a.length>0&&(a=a[0]),a.classList.add(l.isHorizontal()?r.horizontalClass:r.verticalClass),a&&(o=a.querySelector(classesToSelector(l.params.scrollbar.dragClass)),o||(o=createElement("div",l.params.scrollbar.dragClass),a.append(o))),Object.assign(s,{el:a,dragEl:o}),r.draggable&&l.params.scrollbar.el&&l.scrollbar.el&&v("on"),a&&a.classList[l.enabled?"remove":"add"](...classesToTokens(l.params.scrollbar.lockClass))}function C(){const s=l.params.scrollbar,e=l.scrollbar.el;e&&e.classList.remove(...classesToTokens(l.isHorizontal()?s.horizontalClass:s.verticalClass)),l.params.scrollbar.el&&l.scrollbar.el&&v("off")}e({scrollbar:{el:null,dragSize:"auto",hide:!1,draggable:!1,snapOnRelease:!0,lockClass:"swiper-scrollbar-lock",dragClass:"swiper-scrollbar-drag",scrollbarDisabledClass:"swiper-scrollbar-disabled",horizontalClass:"swiper-scrollbar-horizontal",verticalClass:"swiper-scrollbar-vertical"}}),l.scrollbar={el:null,dragEl:null},r("init",(()=>{!1===l.params.scrollbar.enabled?E():(D(),u(),b())})),r("update resize observerUpdate lock unlock",(()=>{u()})),r("setTranslate",(()=>{b()})),r("setTransition",((s,e)=>{!function(s){l.params.scrollbar.el&&l.scrollbar.el&&(l.scrollbar.dragEl.style.transitionDuration=`${s}ms`)}(e)})),r("enable disable",(()=>{const{el:s}=l.scrollbar;s&&s.classList[l.enabled?"remove":"add"](...classesToTokens(l.params.scrollbar.lockClass))})),r("destroy",(()=>{C()}));const E=()=>{l.el.classList.add(...classesToTokens(l.params.scrollbar.scrollbarDisabledClass)),l.scrollbar.el&&l.scrollbar.el.classList.add(...classesToTokens(l.params.scrollbar.scrollbarDisabledClass)),C()};Object.assign(l.scrollbar,{enable:()=>{l.el.classList.remove(...classesToTokens(l.params.scrollbar.scrollbarDisabledClass)),l.scrollbar.el&&l.scrollbar.el.classList.remove(...classesToTokens(l.params.scrollbar.scrollbarDisabledClass)),D(),u(),b()},disable:E,updateSize:u,setTranslate:b,init:D,destroy:C})}export{Scrollbar as default};
//# sourceMappingURL=scrollbar.min.mjs.map